<?php
/**
 * Created by PhpStorm.
 * User: xuewl
 * Date: 2018/1/5
 * Time: 18:30
 */

namespace app\notification\behavior;


class ProductOrderReserve
{
    public function run(&$params) {}

    /**
     * 订单抢单成功
     * @param $params
     */
    public function ReviewAfter(&$params) {

        \think\Lang::load(APP_PATH . 'notification/lang/zh-cn.php');
        $lang = \think\Lang::get('notification');
        $notification = $lang['订单抢单成功'];

        $replace = [
            '{{客户姓名}}' => (string) $params->realname,
            '{{产品类型}}' => (string) $params->product->name,
            '{{客户经理姓名}}' => (string) $params->customer_info->customer_realname,
            '{{跟进剩余时间}}' => config('product.product_order_flow_interval')
        ];


        if ($notification['sms'] && $params->customer_info->mobile) {
            $template_id = $notification['sms']['template_id'];
            $template_vars = str_replace(array_keys($replace), $replace, $notification['sms']['template_vars']);
            model('admin/dysms', 'service')->send($params->customer_info->mobile, $template_vars, $template_id);
        }

        if($notification['message']) {
            $title = $notification['message']['title'];
            $content = str_replace(array_keys($replace), $replace, $notification['message']['content']);
            model('message/message', 'service')
                ->send($params->customer_id, $title, $content, $params->uid, [
                    'role' => 2,
                    'order_sn' => $params->sn,
                    'target' => '/pages/customer/product_order/item?sn='.$params->sn
                ]);
        }

//        if($notification['template_message']) {
//            $mini_program = config('wechat.mini_program');
//            $data = [
//                'touser' => $fans['openid'],
//                'miniprogram' => [
//                    'appid' => $mini_program['app_id'],
//                    'pagepath' => '/pages/customer/product_order/item?sn='.$params->sn,
//                ],
//                'template_id' => $notification['template_message']['template_id'],
//                'data' => str_replace(array_keys($replace), $replace, $notification['template_message']['template_vars'])
//            ];
//            queue('app\notification\command\TemplateMessage', $data, 0);
//        }


    }
}
